﻿using DevExpress.ExpressApp;
using DevExpress.Blazor;
using DevExpress.ExpressApp.Blazor.Editors;
using System.Collections;

namespace HC.XAP.Blazor.Server.Controllers.Share
{
    // For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/clsDevExpressExpressAppViewControllertopic.aspx.
    public partial class ColumnResizeModeViewController : ViewController<ListView>
    {
        // Use CodeRush to create Controllers and Actions with a few keystrokes.
        // https://docs.devexpress.com/CodeRushForRoslyn/403133/
        public ColumnResizeModeViewController()
        {
            InitializeComponent();
            // Target required Views (via the TargetXXX properties) and create their Actions.
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
            //if (View.Editor is GridListEditor gridListEditor)
            if (View.Editor is DxGridListEditor gridListEditor)
            {
                //IDxDataGridAdapter dataGridAdapter = gridListEditor.GetDataGridAdapter();
                IDxGridAdapter dxGridAdapter = gridListEditor.GetGridAdapter();
                var data = dxGridAdapter.GridModel.Data as IList;// as ProxyCollection;
                //dataGridAdapter.DataGridModel.ColumnResizeMode = DataGridColumnResizeMode.Component;
                dxGridAdapter.GridModel.ColumnResizeMode = GridColumnResizeMode.ColumnsContainer;

                //禁止显视所有数据,每页最大只显视200行
                if ((dxGridAdapter.GridModel.ShowAllRows && data?.Count >= 200))
                    dxGridAdapter.GridModel.ShowAllRows = false;
            }
        }
        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            base.OnDeactivated();
        }

       
    }
}
